<input type="hidden" name="task.id" value="#(task.id??)" />
<div class="layui-form-item">
	<label class="layui-form-label">标题</label>
	<div class="layui-input-block">
		<input type="text" name="task.taskTitle" value="#(task.task_title??)" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
	</div>
</div>

<div class="layui-form-item">
	<label class="layui-form-label">信息</label>
	<div class="layui-input-block">
		<input type="text" name="task.note" value="#(task.note??)" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
	</div>
</div>

<div class="layui-form-item">
	<label class="layui-form-label">反馈信息</label>
	<div class="layui-input-block">
		<input type="text" name="task.feedbackNote" value="#(task.feedback_note??)" placeholder="请输入" autocomplete="off" class="layui-input">
	</div>
</div>

<div class="layui-form-item">
	<label class="layui-form-label">反馈人</label>
	<div class="layui-input-block">
		<input type="text" name="task.feedbackMan" value="#(task.feedback_man??)" placeholder="请输入" autocomplete="off" class="layui-input">
	</div>
</div>


<div class="layui-form-item">
        <label class="layui-form-label">任务时间</label>
        <div class="layui-input-inline">
            <input type="text" name="task.taskTime" value="#date(task.task_time??,'yyyy-MM-dd HH:mm')" class="layui-input" id="taskTime" placeholder="yyyy-MM-dd HH:mm">
        </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">消息提示</label>
    <div class="layui-input-block">
        <input type="checkbox" name="task.isMsg" value="#(task.is_msg??)" id="is_msg" lay-skin="switch" lay-filter="switchMsg" title="&nbsp;是&nbsp;|&nbsp;否&nbsp;"/>
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">结束归档</label>
    <div class="layui-input-block">
        <input type="checkbox" name="task.isArchiv" value="#(task.is_archiv??)" id = "is_archiv" lay-skin="switch" lay-filter="switchArchiv" title="&nbsp;是&nbsp;|&nbsp;否&nbsp;"/>
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">重要程度</label>
    <div class="layui-input-block">
        <input type="hidden" name="task.important" value="#(task.important??)"/>
        <div id="ID-rate-demo"></div>
    </div>
</div>

<div class="layui-form-item">
	<div class="layui-input-block">
		<button type="button" class="layui-btn" lay-submit lay-filter="demo1">立即提交</button>
	</div>
</div>

<script>
    layui.use(['form', 'layer','jquery','rate','laydate'], function(){
        let form = layui.form;
        let layer = layui.layer;
        let $ = layui.jquery;
        let rate = layui.rate;
        let laydate = layui.laydate;

        laydate.render({
            elem: '#taskTime',
            type: 'datetime',
            fullPanel: true,
            format: 'yyyy-MM-dd HH:mm'
        });

        let isMsg = $("#task_form input[name='task.isMsg']").val();
        let isArchiv = $("#task_form input[name='task.isArchiv']").val();
        let important = $("#task_form input[name='task.important']").val() ?? 0;
        if (isMsg == 1){
            $('#is_msg').prop("checked", true);
        }
        if(isArchiv == 1){
            $('#is_archiv').prop("checked", true);
        }

        rate.render({
            elem: '#ID-rate-demo',
            choose: function(value){
                $("#task_form input[name='task.important']").val(value);
            },
            value: important
        });

        form.on('switch(switchMsg)', function(data){
            $("#task_form input[name='task.isMsg']").val(this.checked ? '1' : '0');
        });

        form.on('switch(switchArchiv)', function(data){
            $("#task_form input[name='task.isArchiv']").val(this.checked ? '1' : '0');
        });

        // 提交事件
        form.on('submit(demo1)', function(data){
            let field = data.field;
            field.isMsg = $("#task_form input[name='task.isMsg']").val();
            field.isArchiv = $("#task_form input[name='task.isArchiv']").val();
            $.post($("#task_form").attr("action"),field,function(result){
                if(result.code===200){
                    layer.msg("插入成功！"+result.msg);
                    var index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                    parent.layer.close(index); // 再执行关闭
                    parent.location.reload();
                }else{
                    layer.msg("插入失败！"+result.msg);
                }
            });
            return false; // 阻止默认 form 跳转
        });
    });
</script>
